﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Class1
    {
        public static void IsExist() {
            string input = Console.ReadLine();
            int letterCount = 0;
            int dightCount = 0;
            int punctuationCount = 0;
            foreach (var item in input)
            {
                if (char.IsLetter(item))
                {
                    letterCount++;
                }
                else if (char.IsDigit(item))
                {
                    dightCount++;
                }
                else if (char.IsPunctuation(item))
                {
                    punctuationCount++;
                }
            }

            Console.WriteLine("你输入的字母有{0}个，输入的数字有{1}个，输入的标点符号有{2}个", letterCount, dightCount, punctuationCount);
        }

        public static void Square() {
            Console.WriteLine("请输入正方形的边长");
            int longer = Exception(true);

            for (int i = 0; i < longer; i++)
            {
                for (int j = 0; j < longer; j++)
                {
                    if (i == 0 || i == longer - 1 || j == 0 || j == longer - 1)
                    {
                        Console.Write("* ");
                    }
                    else
                    {
                        Console.Write("  ");
                    }

                }
                Console.WriteLine();
            }
        }

        public static void Exam() {
            double[] arr = new double[5];
            int count = 0;
            double sum = 0;
            foreach (var user in arr)
            {
                Console.WriteLine("请输入学生{0}成绩", (count + 1));
                double score = Exception();
                arr[count] = score;
                count++;
                sum += score;
            }

            Console.WriteLine("总成绩:{0},平均成绩:{1}", sum, (sum / count));
        }

        public static void OfValue() {
            int[] arr = { 33, 44, 55, 66, 77 };
            int value = Exception(true);
            if (Array.IndexOf(arr, value) != -1)
            {
                Console.WriteLine("结果为:" + Array.IndexOf(arr, value));
            }
            else
            {
                Console.WriteLine("无法查证");
            }
        }

        public static void Insert() {
            
            Console.WriteLine("请输入您要初始化的数组长度:");
            int length = Exception(true);

            int[] arr = new int[length];

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("请输入数字为变量{0}赋值" ,(i + 1));
                arr[i] = Exception(true); 
            }

            Console.WriteLine("输入一排序，输入二判断第一个偶数");
            int key = Exception(true);
            switch (key)
            {
                case 1:
                    Sort(arr);
                    break;
                case 2:
                    IsEven(arr);
                    break;
            }

        }
        public static void Sort(int[] arr) {
            
            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = 0; j < arr.Length - 1 - i; j++)
                {
                    if (arr[j] > arr[j + 1])
                    {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
            Array.Reverse(arr);
            foreach (var item in arr)
            {
                Console.Write(item + " ");
            }
        }

        public static void FullSquare() {
            Console.WriteLine("请输入正方形的边长");
            int longer = Exception(true);

            for (int i = 0; i < longer; i++)
            {
                for (int j = 0; j < longer; j++)
                {
                    Console.Write("* ");
                }
                Console.WriteLine();
            }
        }

        public static void Multiply() {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write( j + " * " + i + "=" + (j * i) + " ");
                }
                Console.WriteLine();
            }
        }

        public static void Rhombus()
        {
            Console.WriteLine("请输入要输出的菱形上半长度");
            int longer = Exception(true);
            for (int m = 1; m <= longer; m++)
            {
                for (int j = 1; j <= longer - m; j++)
                {
                    Console.Write(" ");
                }
                for (int j = 1; j <= 2 * m - 1; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();

            }
            for (int m = longer - 1; m >= 1; m--)
            {
                for (int j = 1; j <= longer - m; j++)
                {
                    Console.Write(" ");
                }
                for (int j = 1; j <= 2 * m - 1; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();

            }
        }

        public static void IsEven(int[] arr) {
            
            for (int i = 0; i < arr.Length; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine("偶数下标为" + i);
                }
            }
        }

        public static void YangHui() {
            int k = 9;
            int[][] a = new int[k][];  
            for (int i = 0; i < a.Length; i++)
                a[i] = new int[i + 1];
            for (int j = 0; j < a.Length; j++)
            {
                a[j][0] = 1;
                a[j][a[j].Length - 1] = 1;
                for (int m = 1; m < a[j].Length - 1; m++)
                    a[j][m] = a[j - 1][m - 1] + a[j - 1][m];
            }
            for (int i = 0; i < a.Length; i++)
            {
                for (int j = 0; j < a[i].Length; j++)
                    Console.Write("{0} ", a[i][j]);
                Console.WriteLine();
            }
        }

        public static int Exception(bool thing) {
            
            while (thing)
            {
                try {
                    int i = int.Parse(Console.ReadLine());

                    return i;
                }
                catch (FormatException e) {
                    Console.WriteLine("请输入一个int类型的数据");
                }
            }

            return 0;
            
        }

        public static double Exception() {
            while (true)
            {
                try
                {
                    double i = double.Parse(Console.ReadLine());
                    return i;
                }
                catch (FormatException e)
                {
                    Console.WriteLine("请输入一个double类型的数据");
                }
            }
        }


    }
}
